package com.example.livingadminmaster.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.livingadminmaster.LivingAdminMasterApplication;
import com.example.livingadminmaster.common.IdWorker;
import com.example.livingadminmaster.dto.MaintenanceDto;
import com.example.livingadminmaster.mapper.FacultyMapper;
import com.example.livingadminmaster.mapper.MaintenanceRecordsMapper;
import com.example.livingadminmaster.pojo.Faculty;
import com.example.livingadminmaster.pojo.MaintenanceRecords;
import com.example.livingadminmaster.service.FacultyService;
import com.example.livingadminmaster.service.MaintenanceRecordsService;
import com.sun.tools.javac.Main;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Service
public class MaintenanceRecordsServiceImpl extends ServiceImpl<MaintenanceRecordsMapper, MaintenanceRecords> implements MaintenanceRecordsService{
    IdWorker idWorker = new IdWorker(1, 1);
    @Autowired
    private MaintenanceRecordsMapper maintenanceRecordsMapper;
    @Autowired
    private FacultyMapper facultyMapper;

    @Transactional(readOnly = true)//该注解助于数据库优化读取性能，并且确保数据不会被修改d
    @Override
    public List<MaintenanceDto> getMaintenanceRecords() {
        List<MaintenanceDto> list=new ArrayList<>();
        LambdaQueryWrapper<MaintenanceRecords> queryWrapper=new LambdaQueryWrapper<>();
//        queryWrapper.eq(MaintenanceRecords::getStatus,1);
        List<MaintenanceRecords> maintenanceRecordList=maintenanceRecordsMapper.selectList(queryWrapper);
        for (MaintenanceRecords maintenanceRecord:maintenanceRecordList){
            MaintenanceDto dto=new MaintenanceDto();
            LambdaQueryWrapper<Faculty> queryWrapper1=new LambdaQueryWrapper<>();
            queryWrapper1.eq(Faculty::getRoomNumber,maintenanceRecord.getRoomNumber()).eq(Faculty::getBuilding,maintenanceRecord.getBuilding());
            dto.setMaintenanceRecords(maintenanceRecord);
            dto.setRoomNumber(maintenanceRecord.getRoomNumber());
            dto.setBuilding(maintenanceRecord.getBuilding());
            list.add(dto);
        }

        return list;
    }
}
